package com.bjkcst.baselib.protocolparse.bean;

import com.bjkcst.baselib.protocolparse.DataProcessUtils;
import com.bjkcst.baselib.protocolparse.annotation.BeanFieldBitAnnotation;

/**
 * @author: zgx
 * @email: zhougaoxing@bjkcst.com
 * @date: 2022/10/19
 * @describe:
 */

public class DefaultBit extends Bit {
    @BeanFieldBitAnnotation(value = "bit0", order = 1)
    public int bit0;
    @BeanFieldBitAnnotation(value = "bit1", order = 2)
    public int bit1;
    @BeanFieldBitAnnotation(value = "bit2", order = 3)
    public int bit2;
    @BeanFieldBitAnnotation(value = "bit3", order = 4)
    public int bit3;
    @BeanFieldBitAnnotation(value = "bit4", order = 5)
    public int bit4;
    @BeanFieldBitAnnotation(value = "bit5", order = 6)
    public int bit5;
    @BeanFieldBitAnnotation(value = "bit6", order = 7)
    public int bit6;
    @BeanFieldBitAnnotation(value = "bit7", order = 8)
    public int bit7;

    public DefaultBit(){}

    public DefaultBit(int value) {
        byte[] bytes = DataProcessUtils.intToByte(value);
        byte byteValue = bytes[0];
        bit0 = DataProcessUtils.getBit(byteValue, 0);
        bit1 = DataProcessUtils.getBit(byteValue, 1);
        bit2 = DataProcessUtils.getBit(byteValue, 2);
        bit3 = DataProcessUtils.getBit(byteValue, 3);
        bit4 = DataProcessUtils.getBit(byteValue, 4);
        bit5 = DataProcessUtils.getBit(byteValue, 5);
        bit6 = DataProcessUtils.getBit(byteValue, 6);
        bit7 = DataProcessUtils.getBit(byteValue, 7);
    }

    public byte getByte() {
        return DataProcessUtils.bitToByte("" + bit7 + bit6 + bit5 + bit4 + bit3 + bit2 + bit1 + bit0);
    }
}
